package team.seekers.skill.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.BeanUtils;
import team.seekers.skill.entity.dao.SectionBlog;
import team.seekers.skill.entity.vo.admin.update.AdminBlogUpdateVO;
import team.seekers.skill.mapper.SectionBlogMapper;
import team.seekers.skill.service.SectionBlogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 这一节的相关博客链接 服务实现类
 * </p>
 *
 * @author hbc
 * @since 2021-02-28
 */
@Service
public class SectionBlogServiceImpl extends ServiceImpl<SectionBlogMapper, SectionBlog> implements SectionBlogService {

    @Override
    public boolean removeBySectionId(String sectionId) {
        QueryWrapper<SectionBlog> wrapper = new QueryWrapper<>();
        wrapper.eq("section_id",sectionId);
        return remove(wrapper);
    }

    @Override
    public List<AdminBlogUpdateVO> listAdminBlogUpdateVOBySectionId(String sectionId) {
        QueryWrapper<SectionBlog> wrapper = new QueryWrapper<>();
        wrapper.eq("section_id",sectionId);
        List<SectionBlog> list = list(wrapper);
        if(list == null){
            return null;
        }
        List<AdminBlogUpdateVO> adminBlogUpdateVOList = new ArrayList<>();
        for (SectionBlog sectionBlog : list) {
            AdminBlogUpdateVO adminBlogUpdateVO = new AdminBlogUpdateVO();
            BeanUtils.copyProperties(sectionBlog,adminBlogUpdateVO);
            adminBlogUpdateVOList.add(adminBlogUpdateVO);
        }
        return adminBlogUpdateVOList;
    }
}
